<style type="text/css">#rightbar{display: none;}.col-lg-8 {width: 100%;}|</style>

<?php 
$javascript->link('/deals/js/camera.js',false);
echo $html->css('/deals/css/camera.css');
echo $html->css('/deals/css/deals.css');
if(!isset($appHtml))
{
	$html->initHelper('AppHtml');
	$appHtml = $html->AppHtml;
}
$currencySymbol = cr("DealConfig.currency_symbol");
?>

<div id="deals_main">
	<div>
	<?php echo $this->element('deals_index_categories', array('categoryId'=>$deal['Deal']['list_category_id'], 'categories' => $categories)); ?>
	</div>
	<h2>
		<?php echo __($deal['Deal']['title']); ?>
	</h2>
	<br/>
	<div class="line">


		<div class="unit deal_details" >
			<div class="line">
					<?php 
					if(isset($deal['DealAsset']) && !empty($deal['DealAsset']))
					{
					?>
					<?php if(count($deal['DealAsset'])>1) { ?>
						<div class="fr camera_wrap" id="deal_slideshow">
							<?php foreach ($deal['DealAsset'] as $dealAsset) { ?>
							<div data-src="<?php echo $dealAsset['file_url'];?>"></div>
							<?php } ?>
						</div>
					<?php 
					} 
					else
					{
					?>
						<div class="image" align="center">
							<?php 
							echo $html->image($deal['DealAsset'][0]['file_url'],array('thumb'=>array('crop'=>false,'width'=>640,'height'=>330),'class'=>'thumbnail','alt'=>sprintf(__("%s picture"),$deal['Deal']['title'])));
							?>
						</div>
					<?php } ?>
				<?php
				}
				?>
			</div>
			<div class="line deal_description">
			<div class="unit size1of2">
					<?php 
					if(strlen($deal['Deal']['description']))
					{
						echo "<h3>".__("Highlights")."</h3>";
						echo $deal['Deal']['description'];
					}
					?>
	<?php 
					if(strlen($deal['Deal']['validity']))
					{
						echo "<h3>".__("Validity")."</h3>";
						echo $appHtml->flayText($deal['Deal']['validity'],150);
					}
					?>
</div>
			<div class="unit size1of2 lastUnit">
					<?php 
					if(strlen($deal['Deal']['fine_print']))
					{
						echo "<h3>".__("Fine Print")."</h3>";
						echo $deal['Deal']['fine_print'];
					}
					?>

				
						<?php 
					if(strlen($deal['Deal']['terms']))
					{
						echo "<h3>".__("Terms")."</h3>";
						echo $appHtml->flayText($deal['Deal']['terms'],150);
					}
					?>
</div>
			</div>
		</div>

			<div class="dealrightCol sidebar">
			<div class="unit box_deal">
				<div  style="text-align: center;" class="deal_left">
					<?php if($showBuyButton) { ?>
					<div>
						<?php
							$btn_text = '<div class="buybtn">'.__("Buy now").'</div>'; 
							
							echo $html->link($btn_text,array("plugin"=>"deals","controller"=>"deal_orders","action"=>"add",$deal['Deal']['id']),array('class'=>'','escape'=>false));
						?>
					</div>
					<div class="clear"></div>
					<div class="line amt">
						<strong><?php $deal['Deal']['finalPrice'] = str_replace(",", "", $deal['Deal']['finalPrice']);?><?php
							echo __("Amount").": ".$currencySymbol."".number_format($deal['Deal']['finalPrice'],2,'.',''); ?> </strong>
					</div>
					<div class="line save">
							<div class="unit size1of3 first">
	
									<span><?php echo __("Regular Price");?></span>
									<br/>
									<?php echo $currencySymbol ."". $deal['Deal']['regular_price']; ?>
	
							</div>
							<div class="unit size1of3">
	 
									<span><?php echo __("Discount");?></span>
									<br/>
									<?php echo $discount."%"; ?>
	
							</div>
							<div class="unit size1of3">
	
									<span><?php echo __("You save");?></span>
									<br/>
									<?php echo $currencySymbol ."". $saving; ?>
	
							</div>
					</div>
					<?php } ?>
					<div class="line counter">
						<?php 
						$dealIsOn = false;
						if(($deal['Deal']['total_quantity']==0) || ($deal['Deal']['total_quantity']>$deal['Deal']['quantity_consumed'])) 
						{
							$dealIsOn = true;
						?>
						<div class="countdownTimer contentBoxLeft boxGreen"
							style="display: block;">
							<div class="countdownTimerBox">
								<i class="ico icoHourGlass"></i> <span class="jtimeLeft timeLeft">
									<span class="countdownLabel"> 
									<?php echo __("This deal will run the next",true); ?>:
								</span> <span class="countdownTime"> <span class="daysLeft">-</span><span
										class="dayLabel">days</span> <span class="hoursLeft">-</span>:<span
										class="minutesLeft">-</span>:<span class="secondsLeft">-</span>
								</span> <input type="hidden" class="jcurrentTimeLeft"
									value="<?php echo $differenceInMilliSeconds; ?>" />
								</span>
							</div>
	
							<script type="text/javascript">
	                        <!--
	                        $(function() {
	                            $('.jtimeLeft').dealCountdown(1, "<?php echo __("day")?>","<?php echo __("days")?>");
	                        });
	                        //-->
	                    </script>
	
						</div>
						<?php 
						} 
						else
						{
							?>
						<div class="soldOutContainer">
							<div class="soldOutBanner"><?php echo __("SOLD OUT"); ?></div>
						</div>
	
						<?php 
						}
						?>
					</div>
					<?php if($showBuyButton) { ?>
					<div class="line count">
						<div id="contentDealStatusBox" class="contentBoxLeft boxGreen">
							<div class="soldAmount">
								<span id="jDealSoldAmount"><?php
	
								$qty_cons = $deal['Deal']['quantity_consumed'];
								$available = $deal['Deal']['total_quantity'];
								$msg = $qty_cons;
								if($available>0)
								{
									$msg = $qty_cons . __(" out of ") . $available;
								}
								echo $msg;
								?> </span> <?php echo __("Bought!")?>
							</div>
	
							<?php //if($dealIsOn == true) { ?>
							<div id="dealSuccessful" class="dealSuccessful">
								<span id="dealTookPlace" style="display: none"> <?php echo __("The %s was completed!"); ?></span>
								<div id="dealTakePlace">
									<i class="big bigDealCheck"></i><?php echo __("Deal is on!"); ?>
								</div>
							</div>
							<?php //} else { ?>
							<div id="dealUnsuccessful" class="dealUnsuccessful">
								<div id="dealUnsuccessfulText" style="display: none">
									<i class="big bigDealCheck"></i><?php echo __("Deal is finished"); ?>
								</div>
							</div>
							<?php //} ?>
						</div>
					</div>
	
					<?php } ?>
					<div class="share_actions">
						<span><?php echo __("Share with friends"); ?></span>
						<br>
						<script type="text/javascript">var switchTo5x=true;</script>
						<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
						<script type="text/javascript">stLight.options({publisher: "fa18b95c-f879-47b6-875f-0b41ebda6416", doNotHash: true, doNotCopy: true, hashAddressBar: false});</script>
						
						<span class='st_facebook' displayText='Facebook'></span>
						<span class='st_twitter' displayText='Twitter'></span>
						<span class='st_email' displayText='eMail'></span>
					</div>
				</div>
			</div>
			<div class="clear"></div>
			<br/>
			<?php
			/*
				if(isset($section))
				{
					echo $section->render('right_sidebar');
				}
			*/
			?>
		</div>

	</div>
	<div class="listing_details line">
<h3><?php echo __("Business Information"); ?></h3>
<?php if($deal['Listing']['id'] == '')  { ?>
		<div class="left_info fl">

		</div>
		<div class="right_info fl">
			This business listing has been deleted from our database.
		</div>
<?php } else { ?>
		<div class="left_info fl">
			<?php 
			//$listingImage = $html->image($deal['Listing']['branch_image'],array('thumb'=>array('crop'=>true,'width'=>100,'height'=>100),'alt'=>sprintf(__("%s"),$deal['Listing']['title'])));
			$listingImage = $html->image($deal['Listing']['image'],array('thumb'=>array('crop'=>true,'width'=>100,'height'=>100),'alt'=>sprintf(__("%s"),$deal['Listing']['title'])));
			echo $html->link("<div class='image' align='center'>".$listingImage."</div>",$html->url($deal['Listing']['viewUrl']),array("target"=>"_blank","escape"=>false));
			?>
		</div>
		<div class="right_info fl">
			<?php 
			echo $html->link("<div class='title'>".$deal['Listing']['title']."</div>",$html->url($deal['Listing']['viewUrl']),array("target"=>"_blank","escape"=>false));
			?>
			<?php 
			echo $html->link(__("Click here to see more business information"),$html->url($deal['Listing']['viewUrl']),array("target"=>"_blank","escape"=>false));
			?>
		</div>
<?php } ?>
	</div>
	<div class="clear"></div>
</div>
<script>
$(document).ready(function(){
	$("#deal_slideshow").camera({
		portrait: true,
		transPeriod: 1500,
		time: 4000,
		fx: 'scrollRight',
		loader: 'none',
		'height' : '330px',
		//'loader' : 'bar',
		'pagination' : false,
		//'thumbnails' : true
	});
	
});
</script>

<script>
(function ($) {
    $.fn.dealCountdown = function (params) {
        var args = Array.prototype.slice.call(arguments);
        return this.each(function () {
            new $.DealCountdown(this, args);
        });
    };
    $.DealCountdown = function (obj, options) {
        var timerTimeLeft = 0;
        var currentTimeLeft = 0;
        var secondsForTimer = 1000;
        var singleDayLabel = "day";
        var pluralDayLabel = "days";
        var timerType = 2;
        currentTimeLeft = $(obj).find('.jcurrentTimeLeft').val();
        timerType = options[0]
        if (timerType === 1) {
            singleDayLabel = options[1];
            pluralDayLabel = options[2];
        }
        setInitialDealTimer(obj);
        timerTimeLeft = setInterval(function () {
            setDealTimer(obj);
        }, secondsForTimer);

        function setDealTimer(obj) {
            currentTimeLeft = parseInt(currentTimeLeft - secondsForTimer);
            if (currentTimeLeft <= 0) {
                if (timerType === 1) {
                    $(obj).find('.daysLeft').empty();
                    $(obj).find('.dayLabel').empty();
                }
                $(obj).find('.hoursLeft').empty().append("00");
                $(obj).find('.minutesLeft').empty().append("00");
                $(obj).find('.secondsLeft').empty().append("00");
                clearInterval(timerTimeLeft);
            } else {
                displayTimes(obj, currentTimeLeft);
            }
        };

        function setInitialDealTimer(obj) {
            if (currentTimeLeft <= 0) {
                clearInterval(timerTimeLeft);
            } else {
                displayTimes(obj, currentTimeLeft);
            }
        };

        function displayTimes(obj, remainingMilliseconds) {
            var wholeSeconds = parseInt(currentTimeLeft / 1000);
            var wholeMinutes = parseInt(currentTimeLeft / 60000);
            var wholeHours = parseInt(wholeMinutes / 60);
            var seconds = parseInt(wholeSeconds % 60);
            var minutes = parseInt(wholeMinutes % 60);
            var days = parseInt(wholeHours / 24);
            var hours = parseInt(wholeHours % 24);
            if (timerType === 1) {
                if (days > 0) {
                    $(obj).find('.daysLeft').empty().append(days);
                    if (days === 1) {
                        $(obj).find('.dayLabel').empty().append(" " + singleDayLabel + " ");
                    } else if (days > 1) {
                        $(obj).find('.dayLabel').empty().append(" " + pluralDayLabel + " ");
                    }
                } else {
                    $(obj).find('.daysLeft').empty();
                    $(obj).find('.dayLabel').empty()
                }
            }
            if (timerType === 0) {
                hours = wholeHours;
            }
            if (hours < 10) {
                $(obj).find('.hoursLeft').empty().append("0" + hours);
            } else {
                $(obj).find('.hoursLeft').empty().append(hours);
            }
            if (minutes < 10) {
                $(obj).find('.minutesLeft').empty().append("0" + minutes);
            } else {
                $(obj).find('.minutesLeft').empty().append(minutes);
            }
            if (seconds < 10) {
                $(obj).find('.secondsLeft').empty().append("0" + seconds);
            } else {
                $(obj).find('.secondsLeft').empty().append(seconds);
            }
        };
    }
})(jQuery);
</script>


